﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing.Imaging;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using ChoJuRating.View;
using ChongJu.EventManager.Camera;
using ChongJu.EventManager.ModelChange;
using ChongJu.GlobalInfo;
using ChongJu.ImageAnalyze;
using ChongJu.ModelManager.Calibration;
using ChongJu.ModelManager.Camera;
using ChongJu.ModelManager.Rating;
using ChongJu.ModelManager;
using GalaSoft.MvvmLight.Threading;
using Microsoft.Practices.Prism.Commands;
using Public.Logger;
using Public.MvvmBase;
using Public.Tools;
using ChongJu.Camera;
using ChongJu.CameraCalibration;

namespace ChoJu.Single.ViewModel
{
    public class CalibrationVM : PropertyChangedBase
    {
        /// <summary>
        /// 委托定义，用于控制界面元素
        /// </summary>
        public delegate void ScrollToEnd();
        public ScrollToEnd FocusLastItem = null;

        private string _imgPath;
        private CalibrationSDKModel _currentCalModel;
        private CalibrationService _service;

        private bool _isRun;
        private int _imageCount;
        private int _imageTotalCount;
        private DateTime? _imgRevice; //接收最新照片的时间

        public CalibrationVM()
        {
            StartCommand = new DelegateCommand(StartFunction);
            SaveRGBCommand = new DelegateCommand(SaveRGBFunction);
            StopCommand = new DelegateCommand(StopFunction);
            ClearDataCommand = new DelegateCommand(ClearDataFunction);
            DetailCommand = new DelegateCommand(DetailFunction);
            UploadResultCommand = new DelegateCommand(UploadResultFunction);
            SaveGreyCommand = new DelegateCommand(SaveGreyImage);

            TestData = new ObservableCollection<CalibrationSDKModel>();
            TestViewData = new ObservableCollection<CaliNewSDKViewModel>();
            _imgPath = Path.Combine("C:\\", "CalibrationImage");
            _service = new CalibrationService();
            RunLogs = new ObservableCollection<RunLogModel>();
            CurrentWorkMod = GlobalVar.CurrentRunType;
            //DllVersion = _service.GetVersion();

            Camera.Instance.ImageCallBackEvent += Instance_ImageCallBackEvent;
            CameraEvent.CameraRGBEvent += CameraEvent_CameraRGBEvent;
            ExchangeModEvent.ExchangeModEventReport += ExchangeModEvent_ExchangeModEventReport;


        }


        #region Property 

        /// <summary>
        /// 当前工作模式
        /// </summary>
        public RunTypeEnum CurrentWorkMod
        {
            get { return _currentWorkMod; }
            set { _currentWorkMod = value; OnPropertyChanged(() => CurrentWorkMod); }
        }
        private RunTypeEnum _currentWorkMod;

        /// <summary>
        /// 测试数据
        /// </summary>
        public ObservableCollection<CalibrationSDKModel> TestData
        {
            get { return _testData; }
            set { _testData = value; OnPropertyChanged(() => TestData); }
        }
        private ObservableCollection<CalibrationSDKModel> _testData;

        /// <summary>
        /// 测试数据(查看用)
        /// </summary>
        public ObservableCollection<CaliNewSDKViewModel> TestViewData
        {
            get { return _testViewData; }
            set { _testViewData = value; OnPropertyChanged(() => TestViewData); }
        }
        private ObservableCollection<CaliNewSDKViewModel> _testViewData;

        /// <summary>
        /// 测试次数
        /// </summary>
        public int TestCount
        {
            get { return _testCount; }
            set { _testCount = value; OnPropertyChanged(() => TestCount); }
        }
        private int _testCount;

        /// <summary>
        /// 校准dll版本号
        /// </summary>
        public string DllVersion
        {
            get { return _dllVersion; }
            set { _dllVersion = value; OnPropertyChanged(() => DllVersion); }
        }
        private string _dllVersion;

        public int CalibrationCount
        {
            get { return _calibrationCount; }
            set { _calibrationCount = value; OnPropertyChanged(() => CalibrationCount); }
        }
        private int _calibrationCount;

        /// <summary>
        /// 当前烟叶图片
        /// </summary>
        public string CurrentImage
        {
            get { return _currentImage; }
            set { _currentImage = value; OnPropertyChanged(() => CurrentImage); }
        }
        private string _currentImage;

        /// <summary>
        /// 手动设置的R值
        /// </summary>
        public int HandR
        {
            get { return _handR; }
            set { _handR = value; OnPropertyChanged(() => HandR); }
        }
        private int _handR;

        /// <summary>
        /// 手动设置的G值
        /// </summary>
        public int HandG
        {
            get { return _handG; }
            set { _handG = value; OnPropertyChanged(() => HandG); }
        }
        private int _handG;

        /// <summary>
        /// 手动设置的B值
        /// </summary>
        public int HandB
        {
            get { return _handB; }
            set { _handB = value; OnPropertyChanged(() => HandB); }
        }
        private int _handB;

        public bool IsSaveRGB
        {
            get { return _isSaveRGB; }
            set { _isSaveRGB = value; OnPropertyChanged(() => IsSaveRGB); }
        }
        private bool _isSaveRGB;


        /// <summary>
        /// 运行日志
        /// </summary>
        public ObservableCollection<RunLogModel> RunLogs
        {
            get { return _runLogs; }
            set { _runLogs = value; OnPropertyChanged(() => RunLogs); }
        }
        private ObservableCollection<RunLogModel> _runLogs;

        #endregion


        #region Command

        public DelegateCommand StartCommand { get; }

        public DelegateCommand StopCommand { get; }

        public DelegateCommand SaveRGBCommand { get; }


        public DelegateCommand ClearDataCommand { get; }


        public DelegateCommand DetailCommand { get; }
        //上传校准结果
        public DelegateCommand UploadResultCommand { get; }


        public DelegateCommand SaveGreyCommand { get; }

        #endregion


        #region Function

        private void StartFunction()
        {
            if (GlobalVar.GlobalParamer.IsBottom == true)
            {
                Camera.Instance.Stop();
                Camera.Instance.OpneLine2CloseLine1();
                Camera.Instance.Start();
            }

            TestCount = 0;
            _isRun = true;
            GlobalVar.CurrentRunType = RunTypeEnum.Calibration;
            CreateLog("-----* 开始校准 *-----");
            //var bol = _service.Init(CameraConfig.CalibrationCfg);
            //if (bol == true)
            //    CreateLog("初始化校准参数成功");
            //else
            //{
            //    CJMsgBox.ShowDialog("初始化校准参数失败", MsgTitle.Error);
            //    return;
            //}

            GlobalVar.CurrentRunType = RunTypeEnum.Calibration;
            ExchangeModEvent.OnExchangeMod(RunTypeEnum.Calibration);
            _currentCalModel = GetInitModel();
            TestData.Add(_currentCalModel);
            Calibration(_currentCalModel);
        }

        private void SaveRGBFunction()
        {
            var result = TestData.Last();
            CameraConfig.CameraCfg.RedGain = result.CameraR;
            CameraConfig.CameraCfg.GreenGain = result.CameraG;
            CameraConfig.CameraCfg.BlueGain = result.CameraB;
            CameraConfig.CameraCfg.Exposure = result.Expose;
            CameraConfig.CameraCfg.OutDelay = result.OutDelay;
            var bol = CameraConfig.UpdateCameraCfg(CameraConfig.CameraCfg);

            if (bol == false)
            {
                CJMsgBox.ShowDialog("保存相机参数异常", MsgTitle.Warning);
                return;
            }

            bol = WriteConfigToMachine();
            if (bol == false)
                return;

            //重新加载模型
            bol = AnalyzeService.Instance.InitModel(GlobalVar.SiteInfo);
            if (bol == false)
                CJMsgBox.ShowDialog("重新加载模型失败", MsgTitle.Error);

            IsSaveRGB = true;

            CJMsgBox.ShowDialog("保存校准参数完成");
        }

        private bool WriteConfigToMachine()
        {
            var msg = Camera.Instance.SetCalibrationCfg(CameraConfig.CameraCfg);
            if (string.IsNullOrWhiteSpace(msg) == false)
            {
                CJMsgBox.ShowDialog(msg, MsgTitle.Error);
                Logger.Error("【保存RGB】-更新参数到相机失败");
            }

            return msg == null;
        }

        private void StopFunction()
        {
            _isRun = false;
            GlobalVar.CurrentRunType = RunTypeEnum.None;
            ExchangeModEvent.OnExchangeMod(RunTypeEnum.None);
        }

        private void ClearDataFunction()
        {
            TestData?.Clear();
            TestViewData?.Clear();

            HandR = HandG = HandB = 0;
        }

        private void DetailFunction()
        {
            //var detail = new CalibrationDetailView();
            //detail.ShowDialog();
        }

        //上传校准结果
        private async void UploadResultFunction()
        {
            CreateLog("-----* 开始上传校准结果 *-----");
            //获取灰板图片根目录
            DirectoryInfo root = new DirectoryInfo(_imgPath);
            //获取根目录下的所有目录
            DirectoryInfo[] directories = root.GetDirectories();
            if (null == directories || directories.Length == 0)
            {
                CJMsgBox.ShowDialog("不存在灰板图片数据，请检查！", MsgTitle.Warning);
                return;
            }
            //获取最后一次校准的灰板数值
            DirectoryInfo resultDir = directories.FirstOrDefault(dir => dir.CreationTime == directories.Max(y => y.CreationTime));
            FileInfo[] files = resultDir.GetFiles();
            if (null == files || files.Length == 0)
            {
                CJMsgBox.ShowDialog("不存在灰板图片数据，请检查！", MsgTitle.Warning);
                return;
            }

            List<GreyBoardModel> greyBoardModels = await getAndUploadGreyBoards(files);


            CreateLog("-----* 结束上传校准结果 *-----");
        }

        private Task<List<GreyBoardModel>> getAndUploadGreyBoards(FileInfo[] files)
        {

            return Task.Factory.StartNew(() =>
            {
                List<GreyBoardModel> greyBoardModels = new List<GreyBoardModel>();
                foreach (FileInfo file in files)
                {
                    GreyBoardModel greyBoardModel = new GreyBoardModel();

                    greyBoardModel.Id = file.Name;
                    greyBoardModel.RatingDeviceId = GlobalVar.DeviceID;
                    greyBoardModel.UploadTime = DateTime.Now;
                    greyBoardModel.Type = "RESULT";
                    GreyBoardParam greyBoardParam = new GreyBoardParam();
                    int[] ROI = { CameraConfig.CalibrationCfg.X, CameraConfig.CalibrationCfg.Y, CameraConfig.CalibrationCfg.Width, CameraConfig.CalibrationCfg.Height };
                    greyBoardParam.ROI = ROI;
                    greyBoardParam.Collation = 0;//暂时写死
                    greyBoardParam.Describe = 1;//暂时写死
                    var removeRate = CameraConfig.CalibrationCfg.RemoveRate / 100.0;
                    greyBoardParam.LargerRate = removeRate;
                    greyBoardParam.SmallRate = removeRate;
                    greyBoardModel.Param = Tool.ObjectToJson(greyBoardParam);
                    greyBoardModel.FileName = file.Name;
                    greyBoardModel.FileLocalPath = file.FullName;
                    greyBoardModels.Add(greyBoardModel);
                    CreateLog("* 开始上传图片： " + file.Name + " *");
                    CreateLog("* 结束上传图片： " + file.Name + " *");
                }

                return greyBoardModels;
            });
        }

        private void SaveGreyImage()
        {
            try
            {
                var dirs = Directory.GetDirectories(_imgPath);
                if (dirs.Length == 0)
                    return;

                var files = Directory.GetFiles(dirs[dirs.Length - 1]);
                if (files.Length == 0)
                    files = Directory.GetFiles(dirs[0]);

                if (files.Length == 0)
                    return;

                var targetDir = Path.Combine(AppContext.BaseDirectory, "calibraMat");
                if (Directory.Exists(targetDir) == false)
                    Directory.CreateDirectory(targetDir);

                var target = Path.Combine(targetDir, "123456.png");
                File.Copy(files[0], target, true);
            }
            catch (Exception ex)
            {
                CJMsgBox.ShowDialog(ex.Message);
            }
        }

        #endregion


        #region Private Function



        private async void Calibration(CalibrationSDKModel data)
        {
            TestCount++;
            var msg = await CreateDirAndSetCamera(TestCount, data, CameraConfig.CameraCfg);
            if (msg != null)
            {
                CJMsgBox.ShowDialog(msg, MsgTitle.Error);
                return;
            }
            if (_isRun == false)
                return;

            CalibrationSDKModel curModel = TestData.Last();
            bool isLight = curModel != null && curModel.Type == CalibrationEnum.Light;
            data.IsCameraToLight = isLight && curModel != null && curModel.LastCalibrationType != CalibrationEnum.Light;
            if (isLight == true)
            {
                //bol = Light.Instance.Write(data.Luminance);
                //bol = Camera.Instance.SetCalibrationCfg(data.)
                //bol = LightService.Instance.Write(data.Luminance);
                if (msg != null || _isRun == false)
                {
                    CJMsgBox.ShowDialog("调节光源错误", MsgTitle.Error);
                    return;
                }
            }

            Camera.Instance.SetTriggerBySoftware();
            if (CalibrationEnum.Minutely == data.Type)
                data.ImageCount = CameraConfig.CalibrationCfg.Minutely_ImageCount;
            else
                data.ImageCount = CameraConfig.CalibrationCfg.Rough_ImageCount;

            var msg1 = await TakePicture(data.ImageCount); //连拍照片
            if (string.IsNullOrEmpty(msg1) == false || _isRun == false)
            {
                CJMsgBox.ShowDialog($"第{TestCount}次连续拍照{data.ImageCount}张 失败\r\n{msg1}", MsgTitle.Error);
                return;
            }

            msg1 = await _service.Run(data, isLight);
            if (string.IsNullOrEmpty(msg1) == false || _isRun == false)
            {
                CJMsgBox.ShowDialog($"第{TestCount}次解析灰板 失败\r\n{msg1}", MsgTitle.Error);
                return;
            }

            //var result = IsCompleteNew(data);
            var result = data.IsComplete;
            data.ToView().ForEach(q => TestViewData.Add(q));
            OnPropertyChanged(() => TestViewData);
            //一个校准流程包括：光源亮度校准-> 相机校准(粗/精调) -> 光源亮度校准 ->结束（如果光源校准一次不成功则转到第一步）
            if (CalibrationCount >= 2)
            {
                CreateLog($"第{CalibrationCount}次全流程结束校准");
                CreateLog("------* 校验结束 *------");
                Camera.Instance.SetTriggerByLine0();
                SaveRGBFunction(); //校准结束后自动保存RGB值
                return;
            }

            if (result == false)
            {
                var tmp = CloneModel(data);
                TestData.Add(tmp);
                Calibration(tmp);
            }
            else
            {
                Camera.Instance.SetTriggerByLine0();
                CreateLog("------* 校验完成 *------");

                //校准完成之后，自动保存RGB值
                var bol = AnalyzeService.Instance.GetFrist().Analyze.LoadCF();
                if (bol == false)
                    CJMsgBox.ShowDialog("重新加载模型异常");

                SaveRGBFunction();
                GlobalVar.CurrentRunType = RunTypeEnum.None;

                if (GlobalVar.GlobalParamer.IsBottom == true)
                {
                    Camera.Instance.Stop();
                    Camera.Instance.OpneLine1CloseLine2();
                    Camera.Instance.Start();
                }
            }

            FocusLastItem();
        }


        public Task<string> CreateDirAndSetCamera(int index, CalibrationSDKModel model, CameraModel cfg)
        {
            return Task.Factory.StartNew(() =>
            {
                try
                {
                    model.ImageDir = Path.Combine(_imgPath, $"image_{index}");
                    _currentCalModel = model;

                    if (Directory.Exists(model.ImageDir) == true)
                        Directory.Delete(model.ImageDir, true);

                    Directory.CreateDirectory(model.ImageDir);
                    if (Directory.Exists(model.ImageDir) == false)
                        Directory.CreateDirectory(model.ImageDir);

                    //设置相机RGB
                    CameraModel camera = cfg.Clone();
                    camera.RedGain = model.ResultR;
                    camera.GreenGain = model.ResultG;
                    camera.BlueGain = model.ResultB;
                    camera.Exposure = model.Expose;
                    camera.OutDelay = model.OutDelay;
                    var msg = Camera.Instance.SetCalibrationCfg(camera);
                    if (string.IsNullOrEmpty(msg) == false)
                        return msg;
                }
                catch (Exception ex)
                {
                    Logger.Error("创建文件夹和设置相机异常：", ex);
                    return ex.Message;
                }

                return null;
            });
        }

        public CalibrationSDKModel GetInitModel()
        {
            CalibrationSDKModel model = new CalibrationSDKModel();
            model.Index = 1;
            model.StandR = CameraConfig.CalibrationCfg.StandR;
            model.StandG = CameraConfig.CalibrationCfg.StandG;
            model.StandB = CameraConfig.CalibrationCfg.StandB;

            //从UI获取相机初始参数，涉及到手动修改初始校验RGB
            model.CameraR = HandR == 0 ? CameraConfig.CameraCfg.RedGain : HandR;
            model.CameraG = HandG == 0 ? CameraConfig.CameraCfg.GreenGain : HandG;
            model.CameraB = HandB == 0 ? CameraConfig.CameraCfg.BlueGain : HandB;

            model.Luminance = CameraConfig.CameraCfg.Luminance;

            model.X = CameraConfig.CalibrationCfg.X;
            model.Y = CameraConfig.CalibrationCfg.Y;
            model.W = CameraConfig.CalibrationCfg.Width;
            model.H = CameraConfig.CalibrationCfg.Height;

            model.RemoveRate = CameraConfig.CalibrationCfg.RemoveRate;
            model.ImageCount = CameraConfig.CalibrationCfg.Rough_ImageCount;
            model.AllowRange = CameraConfig.CalibrationCfg.Rough_AllowRange;

            model.Expose = CameraConfig.CameraCfg.Exposure;
            model.OutDelay = CameraConfig.CameraCfg.OutDelay;

            model.Type = CalibrationEnum.Light;
            model.LastCalibrationType = CalibrationEnum.Light;
            model.Remark = "灯光校准";
            return model;
        }


        public void CreateLog(string msg)
        {
            DispatcherHelper.CheckBeginInvokeOnUI(() =>
            {
                RunLogs.Add(new RunLogModel() { Message = msg, Time = DateTime.Now });
                OnPropertyChanged(() => RunLogs);
            });
        }

        private CalibrationSDKModel CloneModel(CalibrationSDKModel data, bool isKeep = false, string remark = null)
        {
            var newModel = data.Clone();
            newModel.Remark = remark;
            if (isKeep == false)
            {
                newModel.CameraR = data.ResultR;
                newModel.CameraG = data.ResultG;
                newModel.CameraB = data.ResultB;
                newModel.Luminance = data.Luminance;
                newModel.Expose = data.Expose;
                newModel.OutDelay = data.OutDelay;
            }
            else
            {
                newModel.CameraR = data.CameraR;
                newModel.CameraG = data.CameraG;
                newModel.CameraB = data.CameraB;
                newModel.Luminance = data.ResultLuminance;
                newModel.Expose = data.Expose;
                newModel.OutDelay = data.OutDelay;
            }

            newModel.Index = TestData.Count + 1;
            return newModel;
        }


        private Tuple<bool, CalibrationSDKModel> IsCompleteNew(CalibrationSDKModel data)
        {
            switch (data.LastCalibrationType)
            {
                case CalibrationEnum.Light:
                    return CheckLightComplete(data);
                case CalibrationEnum.Rough:
                case CalibrationEnum.Minutely:
                    return CheckRoughAndMinutelyComplete(data);
                default:
                    CreateLog("IsCompleteNew方法：未知类型校准");
                    return null;
            }
        }

        private Tuple<bool, CalibrationSDKModel> CheckLightComplete(CalibrationSDKModel data)
        {
            CalibrationSDKModel temp;
            if (data.IsComplete == false)
            {
                temp = CloneModel(data, true, "灯光校准");
                temp.LastCalibrationType = temp.Type;
                if (temp.IsCameraToLight == true)
                {
                    //如果是粗调或者精调到光源亮度校准，那么就代表流程走过一次了，那么给CalibrationCount加1
                    CalibrationCount++;
                }

                return new Tuple<bool, CalibrationSDKModel>(false, temp);
            }

            //光源上次的调整步骤是粗/精调，那么直接结束校准流程
            if (data.IsCameraToLight == true)
            {
                string remark = $"第{CalibrationCount + 1}次光源相机校准成功\r\n完成校准！！！";
                data.Remark = remark;
                CreateLog(remark);
                return new Tuple<bool, CalibrationSDKModel>(true, data);
            }

            //光源上次的调整步骤不是精调，那么要重新走一遍流程
            string msg = "灯光校准完成，开始调整相机";
            CreateLog(msg);
            temp = CloneModel(data, remark: msg);
            temp.AllowRange = CameraConfig.CalibrationCfg.Rough_AllowRange;
            //计算电压结果值
            ParserLuminance(TestData.ToList());
            return new Tuple<bool, CalibrationSDKModel>(false, temp);
        }

        private Tuple<bool, CalibrationSDKModel> CheckRoughAndMinutelyComplete(CalibrationSDKModel data)
        {
            CalibrationSDKModel temp;
            if (data.IsComplete == false)
            {
                temp = CloneModel(data, remark: GetCalibrationEnumRemark(data.Type));
                if (CalibrationEnum.Rough == temp.Type)
                {
                    temp.AllowRange = CameraConfig.CalibrationCfg.Rough_AllowRange;
                }
                else if (CalibrationEnum.Minutely == temp.Type)
                {
                    temp.AllowRange = CameraConfig.CalibrationCfg.Minutely_AllowRange;
                }

                return new Tuple<bool, CalibrationSDKModel>(false, temp);
            }
            //校准成功后需要再次校准一次光源，如果光源合规，那么就算校准完毕
            temp = CloneModel(data, true, "相机->灯光");
            //temp.IsComplete = false;
            return new Tuple<bool, CalibrationSDKModel>(true, temp);
        }

        private string GetCalibrationEnumRemark(CalibrationEnum type)
        {
            switch (type)
            {
                case CalibrationEnum.Light:
                    return "光源校准";
                case CalibrationEnum.Rough:
                    return "粗调";
                case CalibrationEnum.Minutely:
                    return "精调";
                default:
                    return "未知校准步骤";
            }
        }


        private Task<string> TakePicture(int count)
        {
            return Task.Factory.StartNew(() =>
            {
                try
                {
                    _imageCount = 0;
                    _imageTotalCount = count;
                    Camera.Instance.TakePicture();
                    _imgRevice = DateTime.Now;
                    while (true && _isRun == true)
                    {
                        //防止相机传输掉帧导致拍照中断
                        if ((DateTime.Now - (DateTime)_imgRevice).Seconds > 3)
                            Camera.Instance.TakePicture();

                        if (_imageCount < count)
                            Thread.Sleep(100);
                        else
                            return null;
                    }

                    return null;
                }
                catch (Exception ex)
                {
                    Logger.Error("拍照异常", ex);
                    return ex.Message;
                }
            });
        }

        private void ParserLuminance(List<CalibrationSDKModel> data)
        {

        }

        private int ContinuousCount(List<CalibrationSDKModel> data)
        {
            if (data == null || data.Count == 0)
                return 0;

            if (data.Count == 1)
                return 1;

            int count = 0;
            for (int i = data.Count; i > 0; i--)
            {
                if (data[i].Index == data[i - 1].Index + 1)
                    count++;
                else
                    return count;
            }

            return count;
        }
        #endregion


        #region event

        private void Instance_ImageCallBackEvent(Bitmap image, DateTime tm)
        {
            if (GlobalVar.CurrentRunType != RunTypeEnum.Calibration ||
                _isRun == false ||
                _imageCount >= _imageTotalCount)
                return;

            Bitmap img = null;
            _imgRevice = DateTime.Now;
            try
            {
                var file = Path.Combine(_imgPath, $"image_{TestCount}", $"{DateTime.Now.ToString("HHmmssfff")}.png");
                img = new Bitmap(image);
                img.Save(file, ImageFormat.Png);
                _imageCount++;

                Thread.Sleep(CameraConfig.CalibrationCfg.PictureInterval);
                Camera.Instance.TakePicture();
            }
            catch (Exception ex)
            {
                Logger.Error("保存图片异常", ex);
            }
            finally
            {
                if (GlobalVar.CurrentRunType == RunTypeEnum.Calibration)
                    image?.Dispose();
                img?.Dispose();
            }
        }

        private void ExchangeModEvent_ExchangeModEventReport(RunTypeEnum obj)
        {
            CurrentWorkMod = obj;
        }

        private void CameraEvent_CameraRGBEvent(int r, int g, int b)
        {
            HandR = r;
            HandG = g;
            HandB = b;
        }

        #endregion
    }
}
